package com.tssup.fesco.search;

import com.tssup.fesco.service.UpdateIndexService;
import com.tssup.fesco.util.TaskLogger;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.JobHander;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * @author jiashen
 */
@JobHander(value="UpdateHotKeyJob")
@Service
public class UpdateHotKeyJob extends IJobHandler {

    @Autowired
    private TaskLogger taskLogger;

    @Autowired
    private UpdateIndexService updateIndexService;

    private void updateHotKeyIndex() {
        updateIndexService.updateHotKeyIndex();
    }

    @Override
    public ReturnT<String> execute(String... params) throws Exception {
        try {
            taskLogger.info("Updating hot key index...");
            updateHotKeyIndex();
            taskLogger.info("Update hot key index completed.");
            return ReturnT.SUCCESS;
        } catch (Exception e) {
            taskLogger.error("Update hot key index get error: ", e);
            return ReturnT.FAIL;
        }
    }
}
